package com.peach.utils;

import com.peach.service.DeviceManage.PushMsgApplicationImpl;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.mybatis.spring.SqlSessionTemplate;

import java.io.InputStream;

/**
 * Created by tao on 2017/12/4.
 */
public class SqlConfig {

    public static SqlSessionTemplate sessionTemplateConfigure () {
        //mybatis的配置文件*********************
        String resource = "MyBatis-Configuration.xml";
        //使用类加载器加载mybatis的配置文件（它也加载关联的映射文件）
        InputStream is = PushMsgApplicationImpl.class.getClassLoader().getResourceAsStream(resource);
        //构建sqlSession的工厂
        SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(is);
        //创建能执行映射文件中sql的sqlSession
        SqlSessionTemplate sessionTemplate = new SqlSessionTemplate(sessionFactory);
        return sessionTemplate;
    }
}
